//
//  YXMineSettingTypeViewController.m
//  CreditCard
//
//  Created by 杨旭 on 2017/12/27.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "YXMineSettingTypeViewController.h"
#import "YXFeedbackView.h"
#import "YXForgotTableView.h"
@interface YXMineSettingTypeViewController ()<UIWebViewDelegate>
@property (nonatomic, strong) UIWebView *webView;
@end

@implementation YXMineSettingTypeViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createLeftBarButtonItemWithImage:@"导航栏_002"];

    [self createUI];
}

- (void)createUI {
    switch (self.typeView) {
        case AboutView:
        {
            self.webView = [[UIWebView alloc] init];
            [UIView animateKeyframesWithDuration:1.0 delay:0.5 options:(UIViewKeyframeAnimationOptionOverrideInheritedDuration) animations:^{
                [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
                    self.webView.frame = CGRectMake(0, 200, 0,0);
                }];
                
                [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:1.0 animations:^{
                    self.webView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight-64);
                }];
                
                // 自动对页面进行缩放以适应屏幕
                _webView.scalesPageToFit = YES;
                
                [self.view addSubview:_webView];
                
                // 创建url
                NSURL *url = [NSURL URLWithString:@"https://www.wzym2m.com/mpos-images/image/about.jpg"];
                
                // 请求url
                NSURLRequest *request = [NSURLRequest requestWithURL:url];
                
                // webview加载url
                [_webView loadRequest:request];
                
            } completion:^(BOOL finished) {
                //NSLog(@"完成");
                
            }];
            
        }
            break;
        case FeedbackView:
        {
            YXFeedbackView *feedbackView = [[YXFeedbackView alloc] initWithFrame:self.view.bounds];
            [self.view addSubview:feedbackView];
            if ([self.title isEqualToString:@"意见反馈"]) {
                feedbackView.textStr.text = @"请输入反馈内容";
                [feedbackView setSubmitBtnClickBlock:^(NSString *content) {
                    //                http://121.196.210.134:8082/mpos/wx/submitAdvise.do
                    NSString *urlStr = @"submitAdvise.do";
                    YXUserInfoModel *model = [YXUserInfoManager getUserInfo];
                    NSDictionary *parameter = @{@"sessionId":model.sessionId,@"advise":content};
                    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:parameter success:^(id responseObject) {
//                        NSLog(@"请求成功%@",responseObject);
                        if (REQUESTDATASUCCESS) {
                            [self showTostMessage:@"反馈成功"];

                        }else {
                            [self showTostMessage:responseObject[@"msg"]];
                        }
                    } failure:^(NSError *error) {
                        NSLog(@"请求失败%@",error);
                        [self showAlertWithTitle:@"提示" Messge:@"维护中，请稍等！"];

                    }];
                    
                }];
            }else if ([self.title isEqualToString:@"举报"]) {
                feedbackView.textStr.text = @"请输入举报内容";
                [feedbackView setSubmitBtnClickBlock:^(NSString *content) {
                    //                http://121.196.210.134:8082/mpos/wx/submitAdvise.do
                    NSString *urlStr = @"submitAdvise.do";
                    YXUserInfoModel *model = [YXUserInfoManager getUserInfo];
                    NSDictionary *parameter = @{@"sessionId":model.sessionId,@"advise":content};
                    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:parameter success:^(id responseObject) {
//                        NSLog(@"请求成功%@",responseObject);
                        if (REQUESTDATASUCCESS) {
                            [self showTostMessage:@"举报成功"];
                            
                        }
                    } failure:^(NSError *error) {
                        NSLog(@"请求失败%@",error);
                        [self showAlertWithTitle:@"提示" Messge:@"维护中，请稍等！"];

                    }];
                    
                }];
                
            }
            

        }
            break;
        case WithdrawalPasswordView:
        {
            NSArray *titleArr = @[@"手 机 号 码",@"获取验证码",@"输入新密码",@"确认新密码"];
            NSArray *contentArr = @[@"请输入手机号码",@"请输入验证码",@"请输入密码",@"请输入密码"];
            YXForgotTableView *wdPwdTableView = [[YXForgotTableView alloc] initWithFrame:self.view.bounds style:(UITableViewStylePlain) withTitleArr:titleArr withContentArr:contentArr];
            [self.view addSubview:wdPwdTableView];
            
            [wdPwdTableView setCodeBtnClickBlock:^(NSString *phone) {
                [self requestSendRegisterSmsCodePhone:phone withTitle:self.title];
            }];
            
            [wdPwdTableView setAddBtnClickBlock:^(NSDictionary *dict) {
                
                NSString *pwd = [[self passwordToMD5:dict[@"password"]] lowercaseString];
                NSString *pwd2 = [[self passwordToMD5:dict[@"password2"]] lowercaseString];
                
                if (dict[@"password"] != dict[@"password2"]) {
                    [self showTostMessage:@"两次输入密码不相同"];
                }else {
                    //  http://121.196.210.134:8082/mpos/wx/modifyPassword.do
                    NSString *urlStr = @"modifyPassword.do";
                    NSDictionary *parameter = @{@"account":dict[@"account"],@"password":pwd,@"password2":pwd2,@"smsCode":dict[@"smsCode"]};
                    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:parameter success:^(id responseObject) {
                        if (REQUESTDATASUCCESS) {
                            [self showTostMessage:responseObject[@"msg"]];
                            
                        }
                    } failure:^(NSError *error) {
                        [self showTostMessage:@"修改失败！"];
                    }];
                    
                }
                
            }];
            
        }
            break;
        case LoginPasswordView:
        {
            NSArray *titleArr = @[@"手 机 号 码",@"获取验证码",@"输入新密码",@"确认新密码"];
            NSArray *contentArr = @[@"请输入手机号码",@"请输入验证码",@"请输入密码",@"请输入密码"];
            YXForgotTableView *loginPwdTableView = [[YXForgotTableView alloc] initWithFrame:self.view.bounds style:(UITableViewStylePlain) withTitleArr:titleArr withContentArr:contentArr];
            [self.view addSubview:loginPwdTableView];
            
            [loginPwdTableView setCodeBtnClickBlock:^(NSString *phone) {
                [self requestSendRegisterSmsCodePhone:phone withTitle:self.title];
            }];

            [loginPwdTableView setAddBtnClickBlock:^(NSDictionary *dict) {
                
                NSString *pwd = [[self passwordToMD5:dict[@"password"]] lowercaseString];
                NSString *pwd2 = [[self passwordToMD5:dict[@"password2"]] lowercaseString];
                
                if (dict[@"password"] != dict[@"password2"]) {
                    [self showTostMessage:@"两次输入密码不相同"];
                }else {
                    //  http://121.196.210.134:8082/mpos/wx/modifyPassword.do
                    NSString *urlStr = @"modifyPassword.do";
                    NSDictionary *parameter = @{@"account":dict[@"account"],@"password":pwd,@"password2":pwd2,@"smsCode":dict[@"smsCode"]};
                    [BX_NetWorkManager requestForPOSTWithUrl:urlStr parameter:parameter success:^(id responseObject) {
                        if (REQUESTDATASUCCESS) {
                            [self showTostMessage:responseObject[@"msg"]];
                        }
                    } failure:^(NSError *error) {
                        [self showTostMessage:@"修改失败！"];
                    }];
                    
                }
                
                
            }];
        }
            break;
        default:
            break;
    }
    
    
}

#pragma mark - 获取短信验证码
- (void)requestSendRegisterSmsCodePhone:(NSString *)phone withTitle:(NSString *)title {
    
    NSString *urlStr;
    if ([title isEqualToString:@"注册"]) {
        //    http://121.196.210.134:8082/mpos/wx/sendRegisterSmsCode.do
        urlStr = @"sendRegisterSmsCode.do";
        
    }else {
        //        http://121.196.210.134:8082/mpos/wx/sendModifySmsCode.do
        urlStr = @"sendModifySmsCode.do";
    }
    NSDictionary *parameter = @{@"phone":phone};
    [BX_NetWorkManager requestForGETWithUrl:urlStr parameter:parameter success:^(id responseObject) {
        if (REQUESTDATASUCCESS) {
            [self showAlertWithTitle:@"提示" Messge:@"手机短信发送成功！"];
        }
    } failure:^(NSError *error) {
        [self showAlertWithTitle:@"提示" Messge:@"维护中，请稍等！"];
    }];
}


@end
